<?php
class System_Registry
{
    private $_data = array();
    protected static $_instance = null;

    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public static function add($config)
    {
        $instance = self::getInstance();
        $instance->_data = array_merge($instance->_data, $config);
    }

    public static function has($name)
    {
        $instance = self::getInstance();
        return isset($instance->_data[$name]) ? true : false;
    }

    public static function get($name)
    {
        $instance = self::getInstance();
        if(!isset($instance->_data[$name])) {
            throw new Exception('Undefined registry name: ' . $name);
        }
        return $instance->_data[$name];
    }

    public static function set($key, $value)
    {
        $instance = self::getInstance();
        $instance->_data[$key] = $value;
        return $instance;
    }

}
